package com.jml.impl;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;



@Component
public class RotationLoadBalancerClient implements JmlLoadBalancerClient {
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public ServiceInstance getSingleAddress(List<ServiceInstance> instances) {
        int index = atomicInteger.incrementAndGet() % instances.size();
        return instances.get(index);
    }
}
